package com.hu.zhcc.shiro.service.xsf.impl;

import com.hu.zhcc.common.entity.Page;
import com.hu.zhcc.common.entity.PageRequest;
import com.hu.zhcc.shiro.dao.xsf.TEvaluateMapper;
import com.hu.zhcc.shiro.entity.xsf.dto.TEvaluateDTO;
import com.hu.zhcc.shiro.entity.xsf.pojo.TEvaluate;
import com.hu.zhcc.shiro.service.xsf.TEvaluateService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Service("tEvaluateService")
public class TEvaluateImpl implements TEvaluateService {
    @Autowired
    private TEvaluateMapper tEvaluateMapper;
    @Override
    public Page<TEvaluateDTO> queryAllTEvaluate(Map<String, Object> paremeters, int offset, int limit) {
        int total = this.tEvaluateMapper.countTEvaluate(paremeters);
        List<TEvaluateDTO> dtoList = null;
        if(total > 0) {
            PageRequest pageRequest = new PageRequest(offset, limit, paremeters, null);
            List<TEvaluate> list = this.tEvaluateMapper.queryAllTEvaluate(pageRequest);
            dtoList = new ArrayList<TEvaluateDTO>(list.size());
            for(TEvaluate tEvaluate : list) {
                TEvaluateDTO dto = new TEvaluateDTO();
                BeanUtils.copyProperties(tEvaluate, dto);
                dtoList.add(dto);
            }
        }
        return new Page<TEvaluateDTO>(total, dtoList);
    }

    @Override
    public TEvaluateDTO geEtById(int id) {
        TEvaluate tEvaluate = this.tEvaluateMapper.getById(id);
        if(tEvaluate == null) {
            return null;
        }
        TEvaluateDTO dto = new TEvaluateDTO();
        BeanUtils.copyProperties(tEvaluate, dto);
        return dto;
    }

    @Override
    public TEvaluateDTO saveTEvaluate(TEvaluateDTO dto) {
        TEvaluate tEvaluate = new TEvaluate();
        BeanUtils.copyProperties(dto, tEvaluate);
        this.tEvaluateMapper.insert(tEvaluate);
        dto.setId(tEvaluate.getId());
        return dto;
    }

    @Override
    public int removeTEvaluate(int id) {
        return tEvaluateMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateTEvaluate(TEvaluate tEvaluate) {

        return tEvaluateMapper.updateByPrimaryKeySelective(tEvaluate);
    }
}
